package org.example.controller;

import org.example.model.User;
import org.example.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/login")
    public String login( String username, String password) {
        String msg = userService.login(username, password);
        return  msg;
    }

    @GetMapping("/getUserList")
    public List<User> getUserList(String username) {
       List<User> userList = userService.getUserList(username);
       return userList;
    }

    @PostMapping("/addUser")
    public String addUser(@RequestBody User user) {
       String msg = userService.addUser(user);
       return msg;
    }

    @DeleteMapping("deleteUser/{id}")
    public String deleteUser(@PathVariable int id) {
       String msg = userService.deleteUser(id);
       return msg;
    }

    @PutMapping("/updateUser")
    public String updateUser(@RequestBody User user) {
       String msg = userService.updateUser(user);
       return  msg;
    }




}
